package com.tansun.easycare.rule.ruleproj.entity;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.tansun.easycare.rule.common.entity.RuleBaseEntity;
import com.tansun.easycare.rule.exception.BizException;

/**
 * 层级结构管理Entity
 * @author lph
 * @version 2019-09-11
 */
public class RuleProjectRank extends RuleBaseEntity<RuleProjectRank> {
	
	private static final long serialVersionUID = 1L;
	private String tid;              //扩展ID
	private String projectCode;		// 规则项目编号
	private String nodeId;   //节点ID
	private String pId;		// 表内关联ID
	private String name;		// 层级名称
	private String moduleType;		// 类型
	private String isenable;		// 是否删除
	private Integer seq;
	
	private boolean open = true;//目录树 true 展开
	private boolean noR;
	private String icon;
	private boolean isParent;
	
	public RuleProjectRank() {
		super();
	}
	public RuleProjectRank(String nodeId,String pId,String name,String projectCode,String moduleType,int seq) {
		this.setNodeId(nodeId);
		this.setPId(pId);
		this.setName(name);
		this.setProjectCode(projectCode);
		this.setIsenable("1");
		this.setModuleType(moduleType);
		this.setSeq(seq);
	}
	public RuleProjectRank(String id){
		super(id);
	}
	public String getProjectCode() {
		return projectCode;
	}
	public void setProjectCode(String projectCode) {
		this.projectCode = projectCode;
	}
	public String getTid() {
		return tid;
	}
	public void setTid(String tid) {
		this.tid = tid;
	}
	public String getNodeId() {
		return nodeId;
	}
	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}
	public String getPId() {
		return pId;
	}
	public void setPId(String pId) {
		this.pId = pId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getModuleType() {
		return moduleType;
	}
	public void setModuleType(String moduleType) {
		this.moduleType = moduleType;
	}
	public String getIsenable() {
		return isenable;
	}
	public void setIsenable(String isenable) {
		this.isenable = isenable;
	}
	public Integer getSeq() {
		initProperties();
		if("true".equals((String)props.get("seq"))) {
			seq = Integer.parseInt( (String)props.get(this.getModuleType()+".seq"));
		}
		return seq;
	}
	public void setSeq(Integer seq) {
		this.seq = seq;
	}
	public boolean getOpen() {
		return open;
	}
	public void setOpen(boolean open) {
		this.open = open;
	}
	
	public boolean getNoR() {
		if("ruleDeploy".equals(this.getNodeId()) 
				|| "ruleTest".equals(this.getNodeId())
				|| "batchTest".equals(this.getNodeId())
				|| "deployOnline".equals(this.getNodeId())
				|| "calculationEngine".equals(this.getNodeId())
				|| "ruleApproval".equals(this.getNodeId())
				|| "ruleApprovalTodoList".equals(this.getNodeId())
				|| "ruleApprovalCompleteList".equals(this.getNodeId())
				|| "logs".equals(this.getNodeId())
				|| "ruleGlobalSearch".equals(this.getNodeId())
				) {
			this.noR = true;
		}else {
			this.noR = false;
		}
		return this.noR;
	}
	public void setNoR(boolean noR) {
		this.noR = noR;
	}
	public String getIcon() {
		initProperties();
		icon = (String) props.get(this.getModuleType()+".icon");
		return icon;
	}
	public void setIcon(String iconSkin) {
		this.icon = iconSkin;
	}
	
	public boolean getIsParent() {
		if("file".equals(this.getModuleType())) {
			this.setIsParent(true);
		}else {
			this.setIsParent(false);
		}
		return isParent;
	}
	public void setIsParent(boolean isParent) {
		this.isParent = isParent;
	}

	Map<String,String> iconMap = new HashMap<>();
	public static Properties props;
	
	public static void initProperties() {
		try {
			if(props==null) {
				Resource resource = new ClassPathResource("/components.properties");//
				props = PropertiesLoaderUtils.loadProperties(resource);
			}
		}catch(Exception e) {
			throw new BizException("不存在配置文件/components.properties");
		}
	}	
}